# -*- coding: utf-8 -*-
import sys
from PySide6 import QtCore
from PySide6.QtWidgets import QWidget,QApplication
from ui import Ui_main

class Main(QWidget, Ui_main):
    """ main """
    def __init__(self):
        super(Main, self).__init__()
        self.setupUi(self)
        # windows set
        self.setFixedSize(self.width(), self.height())          # 固定窗口大小
        self.setWindowFlags(QtCore.Qt.FramelessWindowHint)      # 隐藏主窗口边界
        # window.setWindowFlags(QtCore.Qt.WindowMinimizeButtonHint)

        self.isPressed = False
        # callback connect
        self.btn_close.clicked.connect(self.close)
        self.btn_min.clicked.connect(self.showMinimized)

    def mousePressEvent(self, event):
        self.isPressed = True
        self.startPos = event.globalPosition() .toPoint()
        return QWidget().mousePressEvent(event)

    def mouseReleaseEvent(self, event):
        self.isPressed = False
        return QWidget().mouseReleaseEvent(event)

    def mouseMoveEvent(self, event):
        if self.isPressed:
            if self.isMaximized():
                self.showNormal()

            movePos = event.globalPosition() .toPoint() - self.startPos
            self.startPos = event.globalPosition() .toPoint()
            self.move(self.pos() + movePos)

        return QWidget().mouseMoveEvent(event)
    
if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = Main()
    window.show()
    sys.exit(app.exec())